package com.lei.springbootpractice.controller;

import com.lei.springbootpractice.config.DatabaseInitializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    private DatabaseInitializer databaseInitializer;
    
    @Autowired
    private com.lei.springbootpractice.config.NotificationTableCreator tableCreator;

    @GetMapping("/notification-polling")
    public String notificationPollingTest() {
        return "test/notification-polling-test";
    }
    
    @GetMapping("/global-notification")
    public String globalNotificationTest() {
        return "test/global-notification-test";
    }
    
    @GetMapping("/init-database")
    @ResponseBody
    public ResponseEntity<String> initDatabase() {
        try {
            databaseInitializer.run();
            return ResponseEntity.ok("数据库初始化成功！通知状态表已创建。");
        } catch (Exception e) {
            return ResponseEntity.ok("数据库初始化失败: " + e.getMessage());
        }
    }
    
    @GetMapping("/create-notification-table")
    @ResponseBody
    public ResponseEntity<String> createNotificationTable() {
        try {
            tableCreator.createNotificationTable();
            return ResponseEntity.ok("通知状态表创建成功！");
        } catch (Exception e) {
            return ResponseEntity.ok("通知状态表创建失败: " + e.getMessage());
        }
    }
    
    @GetMapping("/enhanced-notification-test")
    public String enhancedNotificationTest() {
        return "test/enhanced-notification-test";
    }
} 